<?php

namespace App\Models\V1;

use App\Scopes\V1\ValidDataScope;
use Illuminate\Database\Eloquent\Model;

class Faculty extends Model
{
    //
//    protected $connection = 'mysql_center';
    protected $table = 'basic_faculties';

    /**
     * 模型启动函数
     */
    protected static function boot()
    {
        parent::boot();
        static::addGlobalScope(new ValidDataScope);
    }

    /**
     * 可被批量赋值字段（白名单）
     *
     * @var array
     */
    protected $fillable = [
        'code','name','avatar','department_code','mobile','telephone','email','title','specialty'
    ];


    /**
     * 限制数组或JSON输出时，隐藏字段
     *
     * @var array
     */
    protected $hidden = [
        'id','deleted_at',
    ];

    /**
     * 获取关联到用户登录信息
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function adminUser()
    {
        return $this->hasOne(AdminUser::class,'account','code');
    }

    /**
     * 获取该教职工所属部门
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function department() {
        return $this->belongsTo(Department::class,'department_code','code');
    }
}
